<?php

namespace app\Server;

use app\model\T_WMS_STOCK_DOC;

class Outboundkb
{
    public $T_WMS_STOCK_DOC;
    public function __construct()
    {
        $this->T_WMS_STOCK_DOC=(new T_WMS_STOCK_DOC());
    }

    public function index(){
        //待出库:SMT、DIP、总装
        //SMT
        $list1=$this->T_WMS_STOCK_DOC->list1([['a.DOC_NO','like',"OP%"],['a.DOC_STATUS','in',[1,2]],['a.DOC_TYPE','=','DJ11'],['a.PLAN_RECEIVE_DATE','>=',date('Y-m-d 00:00:00',strtotime('-60 day'))],['a.PLAN_RECEIVE_DATE','<=',date('Y-m-d 23:59:59')],['d.MO_DOC','like',"%SMT%"]]);
        $count1=$this->T_WMS_STOCK_DOC->count([['DOC_NO','like',"OP%"],['DOC_STATUS','in',[1,2]],['DOC_TYPE','=','DJ11'],['PLAN_RECEIVE_DATE','>=',date('Y-m-d 00:00:00',strtotime('-60 day'))],['PLAN_RECEIVE_DATE','<=',date('Y-m-d 23:59:59')]]);
        $count1s=count($list1);
        $dataCount1=count($list1);
        $new=$this->unqiue($list1);
        //DIP
        $list2=$this->T_WMS_STOCK_DOC->list1([['a.DOC_NO','like',"OP%"],['a.DOC_STATUS','in',[1,2]],['a.DOC_TYPE','=','DJ11'],['a.PLAN_RECEIVE_DATE','>=',date('Y-m-d 00:00:00',strtotime('-60 day'))],['a.PLAN_RECEIVE_DATE','<=',date('Y-m-d 23:59:59')],['d.MO_DOC','like',"%THT%"]]);
        // $count2=$this->T_WMS_STOCK_DOC->count([['DOC_NO','like',"OP%"],['DOC_STATUS','in',[1,2]],['DOC_TYPE','=','DJ11'],['PLAN_RECEIVE_DATE','>=',date('Y-m-d 00:00:00',strtotime('-60 day'))],['PLAN_RECEIVE_DATE','<=',date('Y-m-d 23:59:59')]]);
        $new2=$this->unqiue($list2);
        $dataCount2=count($list2);
        //总装
        $list3=$this->T_WMS_STOCK_DOC->list1([['a.DOC_NO','like',"OP%"],['a.DOC_STATUS','in',[1,2]],['a.DOC_TYPE','=','DJ11'],['a.PLAN_RECEIVE_DATE','>=',date('Y-m-d 00:00:00',strtotime('-60 day'))],['a.PLAN_RECEIVE_DATE','<=',date('Y-m-d 23:59:59')],['d.MO_DOC','like',"%总装%"]]);
        // $count2=$this->T_WMS_STOCK_DOC->count([['DOC_NO','like',"OP%"],['DOC_STATUS','in',[1,2]],['DOC_TYPE','=','DJ11'],['PLAN_RECEIVE_DATE','>=',date('Y-m-d 00:00:00',strtotime('-60 day'))],['PLAN_RECEIVE_DATE','<=',date('Y-m-d 23:59:59')]]);
        $new3=$this->unqiue($list3);
        $dataCount3=count($list3);
        $data1=['data'=>$new,'dataCount1'=>$dataCount1,'count'=>$count1,'counts'=>$count1s,'data2'=>$new2,'dataCount2'=>$dataCount2,'data3'=>$new3,'dataCount3'=>$dataCount3];
        //获取今日已出库任务单
        //SMT
        $lists1=$this->T_WMS_STOCK_DOC->list1([['a.DOC_STATUS','in',[3,4]],['a.DOC_TYPE','=','DJ11'],['a.CLOSE_TIME','>=',date('Y-m-d 00:00:00')],['a.CLOSE_TIME','<=',date('Y-m-d 23:59:59')],['d.MO_DOC','like',"%SMT%"]]);
        $counts1=count($lists1);
        $count2=$this->T_WMS_STOCK_DOC->count([['DOC_STATUS','in',[3,4]],['DOC_TYPE','=','DJ11'],['CLOSE_TIME','>=',date('Y-m-d 00:00:00')],['CLOSE_TIME','<=',date('Y-m-d 23:59:59')]]);
        $news=$this->unqiue($lists1);
        //DIP
        $lists2=$this->T_WMS_STOCK_DOC->list1([['a.DOC_STATUS','in',[3,4]],['a.DOC_TYPE','=','DJ11'],['a.CLOSE_TIME','>=',date('Y-m-d 00:00:00')],['a.CLOSE_TIME','<=',date('Y-m-d 23:59:59')],['d.MO_DOC','like',"%THT%"]]);
        $counts2=count($lists2);
        $news2=$this->unqiue($lists2);
        //总装
        $lists3=$this->T_WMS_STOCK_DOC->list1([['a.DOC_STATUS','in',[3,4]],['a.DOC_TYPE','=','DJ11'],['a.CLOSE_TIME','>=',date('Y-m-d 00:00:00')],['a.CLOSE_TIME','<=',date('Y-m-d 23:59:59')],['d.MO_DOC','like',"%总装%"]]);
        $counts3=count($lists3);
        $news3=$this->unqiue($lists3);
        $data2=['data'=>$news,'count'=>$count2,'counts1'=>$counts1,'counts2'=>$counts2,'counts3'=>$counts3,'data2'=>$news2,'data3'=>$news3];
        //昨日已出库数量单据数
        //SMT
        $listss1=$this->T_WMS_STOCK_DOC->list1([['a.DOC_STATUS','in',[3,4]],['a.DOC_TYPE','=','DJ11'],['a.CLOSE_TIME','>=',date('Y-m-d 00:00:00',strtotime('-1 day'))],['a.CLOSE_TIME','<=',date('Y-m-d 23:59:59',strtotime('-1 day'))],['d.MO_DOC','like',"%SMT%"]]);
        $countss1=count($listss1);
        $count3=$this->T_WMS_STOCK_DOC->count([['DOC_TYPE','=','DJ11'],['DOC_STATUS','in',[3,4]],['CLOSE_TIME','>=',date('Y-m-d 00:00:00',strtotime('-1 day'))],['CLOSE_TIME','<=',date('Y-m-d 23:59:59',strtotime('-1 day'))]]);
        //DIP
        $listss2=$this->T_WMS_STOCK_DOC->list1([['a.DOC_STATUS','in',[3,4]],['a.DOC_TYPE','=','DJ11'],['a.CLOSE_TIME','>=',date('Y-m-d 00:00:00',strtotime('-1 day'))],['a.CLOSE_TIME','<=',date('Y-m-d 23:59:59',strtotime('-1 day'))],['d.MO_DOC','like',"%THT%"]]);
        $countss2=count($listss2);
        //总装
        $listss3=$this->T_WMS_STOCK_DOC->list1([['a.DOC_STATUS','in',[3,4]],['a.DOC_TYPE','=','DJ11'],['a.CLOSE_TIME','>=',date('Y-m-d 00:00:00',strtotime('-1 day'))],['a.CLOSE_TIME','<=',date('Y-m-d 23:59:59',strtotime('-1 day'))],['d.MO_DOC','like',"%总装%"]]);
        $countss3=count($listss3);
        return ['data1'=>$data1,'data2'=>$data2,'count3'=>$count3,'count3s1'=>$countss1,'count3s2'=>$countss2,'count3s3'=>$countss3];
    }
    //去重
    public function unqiue($data=[]){
        $new=[];
        foreach ($data as $v){
            $name=$v['DOC_NO'];
            if(array_key_exists($name,$new)){
                $new[$name]=$v;
            }else{
                $new[$name]=$v;
            }
        }
        foreach ($new as $k=>$v){
            unset($new[$k]);
            $new[]=$v;
        }
        foreach($new as $k=>$v){
           $new[$k]['PLAN_RECEIVE_DATE']=substr((string)$v['PLAN_RECEIVE_DATE'],0,16);
           $new[$k]['CLOSE_TIME']=substr((string)$v['CLOSE_TIME'],0,16);
           $new[$k]['CREATE_TIME']=substr((string)$v['CREATE_TIME'],0,16);
        }
        return $new;
    }

    public function index2(){
        $list3=$this->T_WMS_STOCK_DOC->list2([['a.DOC_STATUS','in',[1,2]],['a.DOC_TYPE','=','DJ12'],['a.PLAN_RECEIVE_DATE','>=',date('Y-m-d 00:00:00',strtotime('-60 day'))],['a.PLAN_RECEIVE_DATE','<=',date('Y-m-d 23:59:59')]]);
        $count31=$this->T_WMS_STOCK_DOC->count([['DOC_STATUS','in',[1,2]],['DOC_TYPE','=','DJ12'],['PLAN_RECEIVE_DATE','>=',date('Y-m-d 00:00:00',strtotime('-60 day'))],['PLAN_RECEIVE_DATE','<=',date('Y-m-d 23:59:59')]]);
        $count3s=count($list3);
        $data3=['data'=>$list3,'count'=>$count31,'counts'=>$count3s];
        //今日已出库
        $list4=$this->T_WMS_STOCK_DOC->list2([['a.DOC_STATUS','in',[3,4]],['a.DOC_TYPE','=','DJ12'],['a.CLOSE_TIME','>=',date('Y-m-d 00:00:00')],['a.CLOSE_TIME','<=',date('Y-m-d 23:59:59')]]);
        $count41=$this->T_WMS_STOCK_DOC->count([['DOC_STATUS','in',[3,4]],['DOC_TYPE','=','DJ12'],['CLOSE_TIME','>=',date('Y-m-d 00:00:00')],['CLOSE_TIME','<=',date('Y-m-d 23:59:59')]]);
        $count4s=count($list4);
        $data4=['data'=>$list4,'count'=>$count41,'counts'=>$count4s];
        //昨日出库数量
        $list5=$this->T_WMS_STOCK_DOC->list1([['a.DOC_STATUS','in',[3,4]],['a.DOC_TYPE','=','DJ12'],['a.CLOSE_TIME','>=',date('Y-m-d 00:00:00',strtotime('-1 day'))],['a.CLOSE_TIME','<=',date('Y-m-d 23:59:59',strtotime('-1 day'))]]);
        $count4=$this->T_WMS_STOCK_DOC->count([['DOC_TYPE','=','DJ12'],['DOC_STATUS','in',[3,4]],['CLOSE_TIME','>=',date('Y-m-d 00:00:00',strtotime('-1 day'))],['CLOSE_TIME','<=',date('Y-m-d 23:59:59',strtotime('-1 day'))]]);
        $count4s=count($list5);
        return ['data3'=>$data3,'data4'=>$data4,'count4'=>$count4,'count4s'=>$count4s];
    }
}